// pages/submit/submit.js
var app = getApp()


Page({

  /**
   * 页面的初始数据
   */
  data: {

    content:'',
    filePath:[],
    length:0,
    imgs:[],
    show:false,
    locationName:"",
    locationAddress:"",
    latitude:0,
    longitude:0,
    picUrlAll:'',
    date:'',
    time:'',
    id:''
 
  },
  files : [],
   // 获取日期
   bindDateChange: function (e) {
    this.setData({
        date: e.detail.value
    })
  },
  // 获取详细时间
  bindTimeChange: function (e) {
    this.setData({
        time: e.detail.value
    })
  },
  
  subBtn(e){
    console.log(this.data.date + ' ' + this.data.time)
    wx.request({
      url: app.globalData.Baseip+':8882/clue/addClue?situationId='+this.data.id,
      data:{
        discoveryTime:this.data.date + ' ' + this.data.time,
        place:this.data.locationName,
        latitude:this.data.latitude,
        longitude:this.data.longitude,
        album:this.data.picUrlAll,
        content:e.detail.value.content

      },
      method:'POST',
      header: {
       Authorization:app.globalData.header
      },
      success:function(res){
        console.log(res)
        wx.navigateBack({
          delta: 1,
        })
      },
      fail:function(err){
        console.log(err)
      }
    })
  
  },


  submitImage(){
    wx.chooseImage({
      count: 5,
      success:res=>{
        wx.showLoading({
          title: '图片上传中 ',
        })
        var pic = ''
        var piclen = res.tempFilePaths.length
        pic = res.tempFilePaths
        console.log(res)
        this.setData({
          pic:pic
        })
        var picUrlAll=''
       for(var index in pic){

          wx.uploadFile({
            filePath: pic[index],
            name:'file',
            header: {
              "Content-Type": "multipart/form-data",
              Authorization:app.globalData.header
             },
        
            url: app.globalData.Baseip+":8881/file/upload?fileName="+pic[index],
            success:res=>{
              var url = JSON.parse(res.data).data
              // console.log(url)
              picUrlAll=picUrlAll+url+','
              // console.log(index,piclen)

              if(index == piclen-1){
                this.setData({
                  picUrlAll:picUrlAll,
                  show:true
                })
                // console.log(picUrlAll)
                wx.hideLoading()
              }
            },
            fail:err=>{
              console.log(err)
            }
          })
          
         
        }
      
       
       
      },
      fail:err=>{

      }
    })
  },
  getLoction(){
    wx.chooseLocation({
      // type:"gcj02",
      success:(res=>{
        console.log(res)
        this.setData({
          locationName:res.name,
          locationAddress:res.address,
          latitude:res.latitude,
          longitude:res.longitude
        })
      }),
      fail:(err=>{
        console.log(err)
      })
    })
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id:options.id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})